package com.xxg.renrensearch.controller;

import com.xxg.renrensearch.domain.query.GetShopListQuery;
import com.xxg.renrensearch.domain.query.SearchShopListQuery;
import com.xxg.renrensearch.domain.result.BaseResult;
import com.xxg.renrensearch.domain.result.GetShopResult;
import com.xxg.renrensearch.service.ShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 店铺管理接口
 *
 * @author xuxiaogang
 * @date 2021-11-17
 */
@Api(tags = "店铺搜索接口")
@RestController
@RequestMapping("/shopSearch")
public class ShopSearchController {
    private final ShopService shopService;

    public ShopSearchController(ShopService shopService) {
        this.shopService = shopService;
    }

    @ApiOperation("分页查询店铺和店中包含的三件商品")
    @RequestMapping(value = "shopProductListQuery", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE,
            consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({@ApiImplicitParam(name = "getShopListQuery", value = "分页条件", required = true, dataType = "GetShopListQuery")})
    public BaseResult<GetShopResult> shopProductListQuery(@RequestBody @Validated GetShopListQuery getShopListQuery, HttpServletRequest request) {
        String shopId = request.getHeader("shopId");
        getShopListQuery.setShopId(Integer.parseInt(shopId));
        return shopService.getShopProduct(getShopListQuery);
    }

    @ApiOperation("根据关键词分页查询店铺（不含商品）")
    @RequestMapping(value = "shopListQuery", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE,
            consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({@ApiImplicitParam(name = "searchShopListQuery", value = "分页条件", required = true, dataType = "GetShopListQuery")})
    public BaseResult<GetShopResult> shopListQuery(@RequestBody @Validated SearchShopListQuery searchShopListQuery, HttpServletRequest request) {
        String shopId = request.getHeader("shopId");
        searchShopListQuery.setShopId(Integer.parseInt(shopId));
        return shopService.getShop(searchShopListQuery);
    }
}
